﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Forget.Data;

namespace Forget.HRBLL.Model
{
    public partial class EmployeeInfo
    {
        public static readonly string ADDEMPLOYEEINFO = "HR_AddEmployeeInfo";
        public static readonly string EDITEMPLOYEEINFO = "HR_EditEmployeeInfo";
        public static readonly string DELEMPLOYEEINFO = "";
        public static readonly string CHANGESALARY = "";

        #region properties
        [DataParam(32, SqlDbType.Int)]
        public int? EmployeeInfoID { get; set; }

        [DataParam(20, SqlDbType.NVarChar)]
        public string NumberID { get; set; }

        [DataParam(0, SqlDbType.Bit)]
        public bool? Sex { get; set; }

        [DataParam(0, SqlDbType.DateTime)]
        public DateTime Birthday { get; set; }

        [DataParam(0, SqlDbType.Float)]
        public double? Weight { get; set; }

        [DataParam(0, SqlDbType.Float)]
        public double? Height { get; set; }

        [DataParam(20, SqlDbType.NVarChar)]
        public string Party { get; set; }

        [DataParam(50, SqlDbType.NVarChar)]
        public string Place { get; set; }

        [DataParam(0, SqlDbType.DateTime)]
        public DateTime InTime { get; set; }

        [DataParam(32, SqlDbType.Int)]
        public int? EpType { get; set; }

        [DataParam(30, SqlDbType.NVarChar)]
        public string IDCard { get; set; }

        [DataParam(200, SqlDbType.NVarChar)]
        public string Address { get; set; }

        [DataParam(20, SqlDbType.NVarChar)]
        public string Education { get; set; }

        [DataParam(50, System.Data.SqlDbType.NVarChar)]
        public string University { get; set; }            

        [DataParam(20, SqlDbType.NVarChar)]
        public string Profession { get; set; }

        [DataParam(0, SqlDbType.Image)]
        public byte[] Picture { get; set; }

        [DataParam(10, SqlDbType.NVarChar)]
        public string Nation { get; set; }

        [DataParam(32, SqlDbType.Int)]
        public int? DpartNum { get; set; }

        [DataParam(32, SqlDbType.Int)]
        public int? PositionNum { get; set; }

        [DataParam(0, SqlDbType.Bit)]
        public bool? Marry { get; set; }

        [DataParam(0, SqlDbType.Money)]
        public decimal? Salary { get; set; }
        #endregion

        #region 人事档案管理

        /// <summary>
        /// 添加员工信息
        /// </summary>
        /// <param name="eInfo"></param>
        /// <returns></returns>
        public static bool AddEmployeeInfo(EmployeeInfo eInfo)
        {
            List<SqlParameter> parms = Convert<SqlParameter>.ObjectToParms(eInfo);
            try
            {
                if (DataAccess.ExecuteNonQuery(CommandType.StoredProcedure, ADDEMPLOYEEINFO, parms.ToArray()) > 0)
                    return true;
            }
            catch (Exception ex)
            {
                Log.WriteLog("BU.AddEmploy", ex.Message, ex.StackTrace);
            }

            return false;
        }

        /// <summary>
        /// 编辑员工信息
        /// </summary>
        /// <param name="eInfo"></param>
        /// <returns></returns>
        public static bool EditEmployeeInfo(EmployeeInfo eInfo)
        {
            List<SqlParameter> parms = Convert<SqlParameter>.ObjectToParms(eInfo);
            try
            {
                if (DataAccess.ExecuteNonQuery(CommandType.StoredProcedure, EDITEMPLOYEEINFO, parms.ToArray()) > 0)
                    return true;
            }
            catch (Exception ex)
            {
                Log.WriteLog("BU.EditEmploy", ex.Message, ex.StackTrace);
            }
            return false;
        }

        /// <summary>
        /// 删除员工信息
        /// </summary>
        /// <param name="eInfo"></param>
        /// <returns></returns>
        public static bool DelEmployeeInfo(EmployeeInfo eInfo)
        {
            List<SqlParameter> parms = Convert<SqlParameter>.ObjectToParms(eInfo);
            try
            {
                if (DataAccess.ExecuteNonQuery(CommandType.StoredProcedure, EDITEMPLOYEEINFO, parms.ToArray()) > 0)
                    return true;
            }
            catch (Exception ex)
            {
                Log.WriteLog("BU.DelEmploy", ex.Message, ex.StackTrace);
            }
            return false;
        }

        /// <summary>
        /// 薪资管理
        /// </summary>
        /// <param name="eInfo"></param>
        /// <returns></returns>
        public static bool ChangeSalary(EmployeeInfo eInfo)
        {
            SqlParameter[] parms = new SqlParameter[] 
            {
                new SqlParameter(){ ParameterName="@id", SqlDbType= SqlDbType.Int, Size=4, Value=eInfo.EmployeeInfoID},
                new SqlParameter(){ParameterName="@salary",SqlDbType= SqlDbType.Money, Value=eInfo.Salary}
            };
            if (DataAccess.ExecuteNonQuery(CommandType.StoredProcedure, CHANGESALARY, parms) > 0)
                return true;
            return false;
        }
        #endregion
    }
}